<?php
	$url = "https://so.gushiwen.org/shiwenv_94e9aad7a0d2.aspx";
	$html = curlget($url);
	$regular = "/html/body//a//@href";
	
	// $results = xpathregular($html,$regular);
	
	$titlexpath = "//h1";
	$titles = xpathregular($html,$titlexpath);
	// var_dump($titles);
	for ($i = 0; $i < $titles->length; $i++) 
	{
		
		$title = $titles->item($i);
		 // var_dump($title);
		$title = $title->nodeValue;
		 
		echo $title;
		// echo "<br/>";
	}		
	
	$authorsxpath ="//p[@class='source']/a";
	$authors = xpathregular($html,$authorsxpath);
	for ($i = 0; $i < $authors->length; $i++) 
	{
		
		$author = $authors->item($i);
		 // var_dump($author);
		$author = $author->nodeValue;
		echo $author;
		if($i==1)
		{
			break;
		}
	}
		
	$contentxpath ="//div[@class='contson']";
	$contents = xpathregular($html,$contentxpath);
	for ($i = 0; $i < $contents->length; $i++) 
	{
		
		$content = $contents->item($i);
		 // var_dump($content);
		$content = $content->nodeValue;
		echo $content;

		break;

	}	
	// var_dump($result);
	// for ($i = 0; $i < $results->length; $i++) 
	// {
	//  
	// 	$result = $results->item($i);
	// 	 
	// 	$linktext = $result->nodeValue;
	// 	 
	// 	echo $linktext;
	// 	echo "<br/>";
	// }		
	
	function curlget($url)
	{
		$url = "https://so.gushiwen.org/shiwenv_94e9aad7a0d2.aspx";

		$ch = curl_init(); // 2. 设置选项，包括URL

		curl_setopt($ch,CURLOPT_URL,$url);

		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

		curl_setopt($ch,CURLOPT_HEADER,0); // 3. 执行并获取HTML文档内容

		$output = curl_exec($ch); 
		if($output === FALSE )
		{ 
		 echo "CURL Error:".curl_error($ch);

		} // 4. 释放curl句柄
		// echo $output;
		return $output;
		curl_close($ch);
		

	}

	function xpathregular($html,$regular)
	{
		$dom = new DOMDocument();
		 
		//从一个字符串加载HTML
		 
		@$dom->loadHTML($html);
		 
		//使该HTML规范化
		 
		$dom->normalize();
		 
		//用DOMXpath加载DOM，用于查询
		 
		$xpath = new DOMXPath($dom);
		#获取所有的a标签的地址
		$results = $xpath->query($regular);
		// for ($i = 0; $i < $results->length; $i++) 
		// {
		//  
		// 	$result = $results->item($i);
		// 	 
		// 	$linktext = $result->nodeValue;
		// 	 
		// 	echo $linktext;
		// 	echo "<br/>";
		// }			 
		 
		return $results;
	}


?>